const baseURL = 'https://pcapi-xiaotuxian-front-devtest.itheima.net'
// const httpInterceptor = {
// 	invoke(option){
// 		if(!option.url.startsWith('http')){
// 			option.url = baseURL + option.url
// 		}
// 		option.timeout= 10000
// 		option.header = {
// 			'source-client': 'miniapp',
// 			...option.header
// 		}
// 	}
// }
// uni.addInterceptor('request', httpInterceptor)
// uni.addInterceptor('uploadFile', httpInterceptor)

export const http = (option) => {
	return new Promise((resolve, reject) => {
		uni.request({
			url: baseURL + option.url,
			method:option.method || 'GET',
			data: option.data || {},
			header: {'source-client': 'miniapp'},
			success: (res) => {
				if(res.statusCode === 200){
					uni.showToast({
						title:'请求成功'
					})
					resolve(res)
				}else{
					uni.showToast({
						title: res.data.message
					})
				}
			},
			fail: (err) => {
				if(err.statusCode === 400){
					uni.showToast({
						title:'请求失败'
					})
					reject(err)
				}
			}
		})
	})
}